﻿using Finance.Bll;
using Finance.Entity;
using Finance.IBll;
using Finance.UI.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Finance.UI.Web;

namespace Finance.UI.Areas.FinanceManager.Controllers
{
    public class BankController : AreaBaseController
    {
        //
        // GET: /FinanceManager/Bank/
        private IBankCardBll bankCardBll = new BankCardBll();
        private IBankCardBinBll bankCardBinBll=new BankCardBinBll();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult SaveBankCard(string cardNo, string bankName, decimal amount = 0, int id = 0)
        {
            BankCardEntity bankCardEntity = new BankCardEntity();
            bankCardEntity.CardNo = cardNo;
            bankCardEntity.BankName = bankName;
            bankCardEntity.Amount = amount;
            bankCardEntity.Id = id;

            bool success = bankCardBll.Save(bankCardEntity);
            return Json(new {success});
        }

        public ActionResult DeleteBankCard(int id)
        {
            bool success = bankCardBll.Delete(id);
            return Json(new {success });
        }

        public ActionResult LoadBankCardList(string cardNo, int pageIndex = 1, int pageSize = 20)
        {
            var total = 0;
            IEnumerable<BankCardEntity> bankCardEntities = bankCardBll.List(cardNo, pageIndex, pageSize, out total);

            //IEnumerable<BankCardModel> bankCardModels = bankCardEntities.Select(ModelHelper.ToModel);

            return Json(new
                {
                    data = bankCardEntities,
                    total
                });
        }

        //public ActionResult 
    }
}
